﻿using HR60_PanelSoft.Model;
using HR60_PanelSoft.Model.BaseModel;
using HR60_PanelSoft.NetWork.Base;
using HR60_PanelSoft.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HR60_PanelSoft.NetWork.Sender
{
    class Sender_0113:BaseSender
    {
        public Sender_0113(byte panelNo, Panel panel, Scene scene)
        {
            byte[] data = new byte[3];
           // data[]

            String L1 = "F";
            String L2 = "F";
            String L3 = "F";
            String L4 = "F";
            String T1 = "F";
            String T2 = "F";


            List<LoadPin> loadPins = panel.loadPins;

            if (loadPins.Count == 0)
                return;


            int i =0;
            foreach (LoadPin lp in loadPins)
            {
                i++;
                Device device = lp.getConnectedDevice();
                if(device == null)
                    continue;
                if (device.type.exType != ExDeviceType.NULL)
                    continue;

                SceneEvent se = scene.findEventByDevice(device.uuid);
                if (se != null )
                {
                    List<String> attrs = se.attrs;
                    List<String> attrValueKeys = se.attrValueKeys;
                    string value = null;
                    if (CollectionUtils.isBlank(attrValueKeys))
                    {
                        continue;
                    }
                    value = attrValueKeys[0];
                    if(i ==1){
                        L1 =(value);
                    }else if(i ==2){
                        L2 =(value);
                    }else if(i == 3){
                        L3 = (value);
                    }else if(i == 4){
                        L4 = (value);

                    }else if(i == 5){
                        T1 = (value);

                    }else if(i == 6){
                        T2 = (value);

                    }
                } 
            }

            data[0] = Convert.ToByte(L2+L1,16) ;
            data[1] = Convert.ToByte(L4+L3,16) ;
            data[2] = Convert.ToByte(T2 + T1,16);


            this.package = Package.getPackage(0x01, 0x13, panelNo, (byte)(Proj.currentProj.scenes.IndexOf(scene)+1), data);

        }
    }
}
